Skip to content

Fix TI port AES-CTR streaming and hashCopy correctness bugs#10986

Open
dgarske wants to merge 2 commits into
wolfSSL:masterfrom
dgarske:ti_port_fenrir_fixes
Open

Fix TI port AES-CTR streaming and hashCopy correctness bugs#10986
dgarske wants to merge 2 commits into
wolfSSL:masterfrom
dgarske:ti_port_fenrir_fixes

Conversation

@dgarske

@dgarske dgarske commented Jul 23, 2026

Copy link
Copy Markdown
Member

Description

Fixes two bugs in the TI (TivaWare TM4C129 AES/SHA-MD5 hardware) port. Both silently produce wrong output rather than failing, and both trace to PR #7018.

F-3078 - wc_AesCtrEncrypt drops partial streaming input (wolfcrypt/src/port/ti/ti-aes.c)

When AES-CTR is called in streaming fashion and a follow-up chunk does not complete the buffered block (aes->left + sz < WC_AES_BLOCK_SIZE), the leading carry-over branch buffered the new plaintext but never encrypted it, never wrote the caller's output, and never advanced aes->left. The caller saw uninitialized/stale output, and the next call overwrote the still-buffered bytes, silently losing plaintext. Fixed by adding the else path that mirrors the existing tail-handling block: encrypt the partial block with AES_CFG_MODE_CTR_NOCTR (no counter advance), emit the new bytes, and do aes->left += odd.

F-2646 - hashCopy discards accumulated message (wolfcrypt/src/port/ti/ti-hash.c)

hashCopy zeroed msg/used/len and copied only the never-populated hash field, so a copied context finalized to the hash of an empty message instead of the source data. Affects wc_Md5Copy, wc_ShaCopy, wc_Sha224Copy, and wc_Sha256Copy. Fixed by allocating a fresh dst->msg and copying src->len bytes (independent allocation preserves the original anti-double-free intent), matching the reference wc_Sha256Copy in devcrypto_hash.c.

@dgarske dgarske self-assigned this Jul 23, 2026
Copilot AI review requested due to automatic review settings July 23, 2026 20:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes two correctness bugs in the TI (TM4C129/TivaWare) hardware-accelerated crypto port that could silently produce incorrect output: AES-CTR streaming with partial buffered blocks, and hash context copying losing the accumulated message.

Changes:

  • Fix wc_AesCtrEncrypt streaming behavior when a follow-up chunk still doesn’t complete the buffered block (encrypt/emit bytes and advance aes->left without counter advance).
  • Fix TI hashCopy to deep-copy the accumulated message buffer so copied contexts finalize correctly.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
wolfcrypt/src/port/ti/ti-aes.c Adds missing handling for the “still not a full block” carry-over path in CTR streaming.
wolfcrypt/src/port/ti/ti-hash.c Updates TI hash context copying to include buffered message data via independent allocation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +130 to +142
/* copy the accumulated message into a fresh buffer so each descriptor
* owns its own allocation and can be freed independently */
dst->used = src->used;
dst->len = src->len;
if ((src->msg != NULL) && (src->len > 0)) {
dst->msg = (byte*)XMALLOC(src->len, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (dst->msg == NULL)
return MEMORY_E;
XMEMCPY(dst->msg, src->msg, src->len);
}
else {
dst->msg = NULL;
}
@dgarske

dgarske commented Jul 23, 2026

Copy link
Copy Markdown
Member Author

Jenkins retest this please. valgrind with openssl-all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants